<template>
	<div class="msgbox">
		<h3 style="margin:40px auto;">发送消息</h3>
		<el-form :model="form" label-width="100px" :rules="rules">
			<el-form-item label="发送对象:" prop="toperson">
				<el-select v-model="pickto" placeholder="请选择" style="float:left" @change="checkpick()">
					<el-option
						v-for="item in toperson"
						:key="item.id"
						:label="item.name"
						:value="item.id">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item v-if="this.pickto==3" label="发送给经理    :">
				<el-select v-model="pickone" placeholder="请选择" style="float:left">
					<el-option
						v-for="item in mngs"
						:key="item.eid"
						:label="item.ename"
						:value="item.eid">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item v-if="this.pickto==4" label="发送给员工    :">
				<el-select v-model="pickone" placeholder="请选择" style="float:left">
					<el-option
						v-for="item in emps"
						:key="item.eid"
						:label="item.ename"
						:value="item.eid">
					</el-option>
				</el-select>
			</el-form-item>
			
			<el-form-item label="发送内容:" prop="content">
				<el-input v-model="form.content" style="width:400px" autocoplete="off"  @change="checkpick2()"></el-input>
			</el-form-item>
			<el-button type="primary" @click="sureSend()" :disabled="disable">发    送</el-button>
		</el-form>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				me:this.$parent.$parent.$parent.$parent.emp,
				rules:{
					/* 验证的对象 */
					toperson:[
						{ required: true, message: '请选择发送对象！', trigger: 'blur'},
					],
					content:[
						{ required: true, message: '请输入发送内容！', trigger: 'blur'},
						
					],
					
				},
				form:{
					seid:'',
					type:0,
					content:'',
					eid:'',
					state:0,
				},
				toperson:[
					{
					id:1,
					name:'to-everyone'
					},
					{
					id:2,
					name:'to-allmanager'
					},
					{
					id:3,
					name:'to-manager'
					},
					{
					id:4,
					name:'to-one'
					},
				],
				emps:[],
				mngs:[],
				pickto:'',
				pickone:'',
				disable:true,
			};
		},
		created(){
			this.$axios.post("empanddept").then(v=>{
				console.log(v)
				if(v.data){
					this.emps=v.data.emps;
					this.mngs=v.data.mngs;
				}else{
					this.$message.error("出错了！");
				}
			}).catch(ex=>{
				this.$message.error("出错了！");
			})
		}, 
		methods:{
			sureSend(){
				this.form.seid=this.me.eid;
				if(this.pickto==3 || this.pickto==4){
					//alert(this.pickone);
					this.form.eid=this.pickone;
				}
				
				let params={};
				params.form=JSON.stringify(this.form);
				params.pickto=this.pickto;
				this.$axios.post("send",params).then(v=>{
					console.log(v)
					if(v.data){
						this.$message.success("发送成功！")
					}else{
						this.$message.error("出错了！");
					}
				}).catch(ex=>{
					this.$message.error("出错了！");
				})
				this.pickto='';
				this.pickone='';
				this.form={
					seid:this.me.eid,
					type:0,
					content:'',
					eid:'',
					state:0,
				}
			},
			checkpick(){
				this.disable=true
				if(this.pickto!=""){
					this.disable=false
				}
			},
			checkpick2(){
				this.disable=true
				if(this.form.content!=""){
					this.disable=false
				}
			},
		},
	}
</script>

<style>
	.msgbox{
		width:900px;
		height:600px;
		border:1px solid #FFFFFF;
		background:#FFFFFF;
	}
	.msgbox .el-form{
		margin:0 auto;
		width:550px;
	}
	.msgbox .el-input{
		width:400px;
		float:left;
	}
</style>
